﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace SpaceInvade.Ships
{
    //This object will be used to display a health/mana/whatever bar, either vertical or horizontal, the size will depend on the percentage
    //of HP/mana.  By Kevin Hardy, January 2012. Adapted for XNA libraries by Anthony Heber 2/23/2012

    public class HealthBar
    {
        Rectangle rctMe; //Position and size of the HealthBar bool IsHorizontal; 
        Color BackColor; // The background color of the bar (the part that always stays the same size)
        Color ForeColor; // The foreground color of the bar (the part that grows or shrinks depending on the amount of HP/Mana/etc...)
        float CurrentHealth; // Remaining Health
        float MaxHealth; // Maximum Health
        bool IsHorizontal; // If the bar is to be displayed horizontal or vertical

        public HealthBar(Rectangle _Me, bool _IsHorizontal, Color _BackColor, Color _ForeColor,
                        float _CurrentHealth, float _MaxHealth)
        {
            rctMe = _Me;
            IsHorizontal = _IsHorizontal;
            BackColor = _BackColor;
            ForeColor = _ForeColor;
            CurrentHealth = _CurrentHealth;
            MaxHealth = _MaxHealth;
        }


        public void TrackShip(int newX, int newY)
        {
            rctMe.X = newX;
            rctMe.Y = newY;
        }

        public void Draw(SpriteBatch canvas)
        {
            // Draw the health bars at the assigned location (changed via the Track method)
            if (IsHorizontal)
            {
                // If using a Horizontal bar
                // Calculate the remaining percentage of health
                float PercentHealth = CurrentHealth / MaxHealth;
                // Figure out number of pixels to represent percentage of main bar
                int DisplayHealth = (int)(rctMe.Width * PercentHealth);
                Rectangle rctCurrent = new Rectangle(rctMe.X, rctMe.Y, DisplayHealth, rctMe.Height);
                // Draw background rectangle first
                canvas.Draw(Game1.pixel, rctMe, BackColor);
                // Draw remaing health bar
                canvas.Draw(Game1.pixel, rctCurrent, ForeColor);
            }
            else
            {
                // not implimented yet (didn't fee like adjusting the rectangles yet.
                //canvas.Draw(Game1.pixel,new Rectangle(this.X, this.Y + this.Height - (int)(this.Height * (this.CurrentHealth / 100)), this.Width, (int)(this.Height * (this.CurrentHealth / 100))),ForeColor);
            }
        }

        public void setCurrentHealth(float currentHealth)
        {
            this.CurrentHealth = currentHealth;
        }
    }
}
